package guowenlong.golf.ui.personal.changephone.step_two;


import android.os.Bundle;
import android.text.Editable;
import android.widget.Button;
import butterknife.BindView;
import butterknife.OnClick;
import guowenlong.golf.C;
import guowenlong.golf.R;
import guowenlong.golf.base.BaseFragment;
import guowenlong.golf.ui.regist.RegistActivity;
import guowenlong.golf.widget.IOSEditText;
import me.wenlong.mixutils.MixUtils;

public class StepTwoFragment extends BaseFragment<StepTwoPresenter, StepTwoModel> implements
    StepTwoContract.View {

  @BindView(R.id.et_code)
  IOSEditText etCode;
  @BindView(R.id.btn_postCode)
  Button btnPostCode;

  @Override
  public int getLayoutId() {
    return R.layout.fragment_step_two;
  }

  @Override
  public void initView() {
    etCode.setTextChangedAfterListener(new IOSEditText.TextChangedAfterListener() {
      @Override
      public void onTextChangedAfter(Editable s) {
        if (s.toString().length() != 4) {
          btnPostCode.setBackgroundResource(R.drawable.bg_green_regist_normal);
          btnPostCode.setClickable(false);
        } else {
          btnPostCode.setBackgroundResource(R.drawable.bg_green_regist_pressed);
          btnPostCode.setClickable(true);
        }
      }
    });
    etCode.requestFocus();
  }

  @Override
  public void initData(Bundle savedInstanceState) {

  }

  @OnClick(R.id.btn_postCode)
  public void onClick() {
    ((RegistActivity) getActivity()).selectFragment(C.FRAGMENT_REGIST_STEP3);
    MixUtils.mSp.edit().putString(C.CODE, etCode.getText().toString().trim()).commit();
  }
}
